package com.yidu.t299.dao.chr;

import com.yidu.t299.domain.chr.Class;
import com.yidu.t299.domain.chr.Record;
import com.yidu.t299.domain.chr.School;
import com.yidu.t299.domain.chr.StudentManage;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface StudentManageMapper {

    /**
     * 根据主键查询学员信息
     * student_manage -> class & school
     * @param studentId 主键
     * @return 学员信息
     */
    @Select({
            "SELECT *" +
                    " FROM student_manage" +
                    " WHERE student_id = #{studentId}"
    })
    @Results(value = {
            @Result(column = "student_id", property = "studentId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "student_name", property = "studentName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "class_id", property = "classId", jdbcType = JdbcType.INTEGER),
            @Result(column = "school_id", property = "schoolId", jdbcType = JdbcType.INTEGER),
            @Result(column = "record_id",property = "recordId", jdbcType = JdbcType.INTEGER),
            @Result(column = "class_id", property = "aClass", javaType = Class.class
                    , one = @One(select = "com.yidu.t299.dao.chr.ClassMapper.selectByPrimaryKey")),
            @Result(column = "school_id", property = "school", javaType = School.class
                    , one = @One(select = "com.yidu.t299.dao.chr.SchoolMapper.selectByPrimaryKey")),
            @Result(column = "record_id",property = "record" ,javaType = Record.class
                    , one = @One(select = "com.yidu.t299.dao.chr.RecordsMapper.selectByPrimaryKey"))
    })
    StudentManage selectByPrimaryKey(Integer studentId);


    /**
     * 根据学员名称查询学员编号
     * @param studentName 学员名称
     * @return 学员编号
     */
    @Select({
            "SELECT student_id" +
                    " FROM student_manage" +
                    " WHERE student_name = #{studentName}"
    })
    String selectByName(String studentName);
}